package com.yida.system.api;

import java.util.ArrayList;
import java.util.List;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import com.yida.common.core.constant.ServiceNameConstants;
import com.yida.common.core.domain.R;
import com.yida.system.api.domain.SysFile;
import com.yida.system.api.domain.UploadRequest;
import com.yida.system.api.domain.UploadResultDTO;
import com.yida.system.api.factory.RemoteFileFallbackFactory;

/**
 * 文件服务
 *
 * @author yida
 */
@FeignClient(contextId = "remoteFileService", value = ServiceNameConstants.FILE_SERVICE, fallbackFactory = RemoteFileFallbackFactory.class)
public interface RemoteFileService {
    /**
     * 上传文件
     *
     * @param file 文件信息
     * @return 结果
     */
    @PostMapping(value = "/file/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<SysFile> upload(@RequestPart(value = "file") MultipartFile file);

    /**
     * minio上传文件
     *
     * @param bucketName
     * @param fileNames
     * @param files 文件
     * @return
     */
    @PostMapping(value = "/file/minioUpload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    R<ArrayList<UploadResultDTO>> upload(@RequestParam(value = "bucketName") String bucketName, @RequestParam(value = "fileNames", required = false) List<String> fileNames, @RequestPart(value = "files") MultipartFile[] files);

    /**
     * 文件上传，自主选择是否动态地址返回
     * 
     * @param file
     * @param bucketName
     * @param dynamicLinkFlag
     * @return
     */
    @PostMapping(value = "/file/uploadFileDynamicLink", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<SysFile> uploadFileDynamicLink(@RequestPart(value = "file") MultipartFile file, @RequestParam(value = "bucketName") String bucketName, @RequestParam(value = "fileName") String fileName, @RequestParam(value = "dynamicLinkFlag") boolean dynamicLinkFlag);

    /**
     * 获取文件信息
     * 
     * @param request
     * @return
     */
    @PostMapping(value = "/file/getFileInfo", consumes = MediaType.APPLICATION_JSON_VALUE)
    public R<SysFile> getFileInfo(@RequestBody UploadRequest request);

    /**
     * 获取文件组信息
     * 
     * @param request
     * @return
     */
    @PostMapping(value = "/file/getFileInfoList", consumes = MediaType.APPLICATION_JSON_VALUE)
    public R<List<SysFile>> getFileInfoList(@RequestBody UploadRequest request);

    /**
     * 删除文件
     * 
     * @param request
     * @return
     */
    @DeleteMapping(value = "/file/delFile", consumes = MediaType.APPLICATION_JSON_VALUE)
    public R<Boolean> delFile(@RequestBody UploadRequest request);
}
